﻿using System.Linq;
using FacialClub.Models.Entities;
using FacialClub.Models.Interfaces;
namespace FacialClub.Models.Repositories
{
    /// <summary>
    /// Treatment Type Repository
    /// </summary>
    public class TreatmentTypeRepository : ITreatmentTypeRepository
    {
        readonly FacialClubEntities _db = new FacialClubEntities();

        /// <summary>
        /// Get Treatment Type Details by Title
        /// </summary>
        /// <param name="strQuery"></param>
        /// <returns></returns>
        public IQueryable<TreatmentType> FindTreatmentTypeByName(string strQuery)
        {
            return _db.TreatmentTypes.Where(d => d.TreatmentTypeName.Contains(strQuery));
        }

        /// <summary>
        /// Get All Treatment Type
        /// </summary>
        /// <returns></returns>
        public IQueryable<TreatmentType> FindAllTreatmentType()
        {
            return _db.TreatmentTypes;
        }

        /// <summary>
        /// Get Treatment Type by Id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public TreatmentType GetTreatmentTypeById(int id)
        {
            return _db.TreatmentTypes.SingleOrDefault(d => d.TreatmentTypeId == id);
        }

        /// <summary>
        /// Add Treatment Type in the Database
        /// </summary>
        /// <param name="treatmentType"></param>
        public void Add(TreatmentType treatmentType)
        {
            _db.TreatmentTypes.AddObject(treatmentType);
        }

        /// <summary>
        /// Delete Treatment Type from Database
        /// </summary>
        /// <param name="treatmentType"></param>
        public void Delete(TreatmentType treatmentType)
        {
            _db.TreatmentTypes.DeleteObject(treatmentType);
        }

        /// <summary>
        /// Save Treatment Type in the database
        /// </summary>
        public void Save()
        {
            _db.SaveChanges();
        }
    }
}